package com.runa.rccprotocol.dto.zhongrun;

import com.runa.protocol.dto.IResponseData;
import com.runa.protocol.util.ByteUtil;
import com.runa.rccprotocol.dto.ConcentratorRequestData;

/**
 * @author diandian
 * @Date 2022/5/7 14:01
 */
public class ZhongRunEquRequestData extends ConcentratorRequestData {
    public ZhongRunEquRequestData(String address) {
        super(address);
    }

    private byte[] requestData;

    @Override
    public byte[] getData() {
        return this.requestData;
    }

    @Override
    public boolean check(IResponseData data) {
        return false;
    }

    public void readHeatMeter(String meterNo) {
        //FE FE FE FE 68 20 83 11 02 20 00 11 11 01 03 1F 90 00 13 16
        requestData = new byte[]{(byte) 0xFE, (byte) 0xFE, (byte) 0xFE, (byte) 0xFE,
                0x68,0x20,
                0,0,0,0,
                0x0,0x11,0x11,0x01,0x03, 0x1F, (byte) 0x90,0x00,
                0,
                0x16};
        ByteUtil.tenstringToBcd(requestData, meterNo, 6, false);
        requestData[18] = ByteUtil.sum(requestData, 4, 15);
        setHaveResult(true);
    }

    public static void main(String[] args) {
        String s = "20021183";
        ZhongRunEquRequestData re = new ZhongRunEquRequestData("");
        re.readHeatMeter(s);
        System.out.println(ByteUtil.byteToHexString(re.requestData));

    }
}